/*D6qijQE+tseVhRgdMUhc8EcdJ0y7KCHGpLLwYl1Pjt+FAmkQ/+lbqG/uBzJ0g8AL*/
/*
 * @Author: xiahui 
 * @PageInfo: 卡片删除 
 * @Date: 2019-01-17 09:37:38 
 * @Last Modified by: zhr
 * @Last Modified time: 2021-10-22 14:22:28
 */
import { ajax } from 'nc-lightapp-front';
import { URL, AREA, DATASOURCECACHE, FIELDS, CACHESTATUS, PAGECODE } from '../../constance';
import { getNextId } from '../../../../../scmpub/scmpub/pub/cache';
import pageInfoClick from './pageInfoClick';
import { showSuccessInfo, showSingleDeleteDialog } from '../../../../../scmpub/scmpub/pub/tool/messageUtil';
import { setCardCacheData } from '../../utils/cardPageUtil';
import { getLangByResId } from '../../../../../scmpub/scmpub/pub/tool/multiLangUtil';

export default function deleteBtnClick(props) {
	showSingleDeleteDialog({
		beSureBtnClick: () => {
			let reqData = {
				infos: [
					{
						id: props.form.getFormItemsValue(AREA.cardFormId, FIELDS.pk_ct_pu).value,
						ts: props.form.getFormItemsValue(AREA.cardFormId, FIELDS.ts).value
					}
				]
			};

			ajax({
				url: URL.delete,
				data: reqData,
				success: (res) => {
					if (res.success && res.data) {
						let source = this.props.getUrlParam('source');
						// 根据当前id,获取下个id
						let cbillid = res.data.successIds[0];
						let nextId = getNextId(props, cbillid, DATASOURCECACHE.dataSourceListCacheKey);
						// 删除当前页缓存数据
						setCardCacheData.call(this, props, res.data, CACHESTATUS.delete);
						if (source == URL.ref20 || source == URL.ref28) {
							let pagecode = source == URL.ref20 ? PAGECODE.ref20Pagecode : PAGECODE.ref28Pagecode;
							if (props.transferTable.getTransformFormAmount(AREA.cardLeftId) == 1) {
								// 转单-剩一条时，返回上级页面
								window.onbeforeunload = null;
								props.pushTo(source, { pagecode: pagecode });
							} else {
								props.transferTable.setTransformFormStatus(AREA.cardLeftId, {
									status: false,
									onChange: (current, next) => {
										showSuccessInfo(getLangByResId(this, '4004PURDAILY-000010')); /* 国际化处理： 删除成功*/
									}
								});
							}
						} else {
							showSuccessInfo(getLangByResId(this, '4004PURDAILY-000010')); /* 国际化处理： 删除成功*/
							// 查询下一页数据
							pageInfoClick.call(this, props, nextId);
						}
					}
				}
			});
		}
	});
}

/*D6qijQE+tseVhRgdMUhc8EcdJ0y7KCHGpLLwYl1Pjt+FAmkQ/+lbqG/uBzJ0g8AL*/